package cn.zc.auth.service.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

/**
 * @author: e
 * @date: 2021/12/23
 * @description:
 */

@Configuration
@EnableGlobalMethodSecurity(securedEnabled = true,prePostEnabled = true)
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

    //注入一个密码加密器
    @Bean
    public BCryptPasswordEncoder bCryptPasswordEncoder(){
        return new BCryptPasswordEncoder();
    }



//    //注入密码模式策略
//    @Bean
//    public AuthenticationManager authenticationManager() throws Exception {
//        return super.authenticationManagerBean();
//    }


    //安全策略
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.csrf().disable()                       //关闭csrf跨域
            .authorizeRequests()
            .antMatchers("/**").permitAll()
                .antMatchers("/**").permitAll()
            .anyRequest().authenticated();
//            .and()
//            .formLogin()                                            //允许表单提交
//            .successForwardUrl("/logins");
//            .loginPage("/logins");                                   //自定义登录页面
    }
}
